package baidu.ui.core
{
    import flash.display.*;

    public class BSkin extends BUI
    {
        protected var skinInstance:DisplayObject;
        protected var _autoSize:Object = false;

        public function BSkin()
        {
            return;
        }

        public function get autoSize() : Object
        {
            return this._autoSize;
        }

        public function set autoSize(param1:Object) : void
        {
            this._autoSize = param1;
            invalidate(Invalidation.SIZE);
            return;
        }

        override protected function draw() : void
        {
            if (isInvalid(Invalidation.STYLES, Invalidation.STATE))
            {
                this.drawSkin();
                invalidate(Invalidation.SIZE, false);
            }
            if (isInvalid(Invalidation.SIZE))
            {
                this.drawLayout();
            }
            super.draw();
            return;
        }

        protected function drawLayout() : void
        {
            if (this.skinInstance)
            {
                if (this._autoSize)
                {
                    width = this.skinInstance.width;
                    height = this.skinInstance.height;
                }
                else
                {
                    this.skinInstance.width = _width;
                    this.skinInstance.height = _height;
                }
            }
            return;
        }

        protected function drawSkin() : void
        {
            var _loc_1:* = this.skinInstance;
            this.skinInstance = getSkinInstance(getStyleValue("skin"));
            if (this.skinInstance)
            {
                addChildAt(this.skinInstance, 0);
            }
            if (_loc_1 != null && _loc_1 != this.skinInstance)
            {
                removeChild(_loc_1);
            }
            return;
        }

    }
}
